#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+5,B=505,INF=1e9;
int f[maxn];
#define VI vector<int>
#define SI set<int>
VI e[maxn];
SI shit[maxn];
int n,K=B-5,pd[maxn],sze[maxn];
void merge(SI &A,SI &B){
	if(A.size()<B.size())for(auto u:A)B.insert(u);
	else {for(auto u:B)A.insert(u);swap(A,B);}
}
int cmp(int x,int y){
	if(y==-1)return 1;
	if(f[x]!=f[y])return f[x]>f[y];
	return pd[x]>pd[y];
}
void dfs(int u,int fa){
	sze[u]=1;
	for(auto v:e[u])if(v!=fa){
		dfs(v,u);
		merge(shit[v],shit[u]);
		shit[u].insert(v);
		sze[u]+=sze[v];
	}
	int mx1=0,mx2=0,p1=-1,p2=-1;
	for(auto x:shit[u]){
		if(cmp(x,p1))mx2=mx1,mx1=f[x],p2=p1,p1=x;
		else if(cmp(x,p2))mx2=f[x],p2=x;
	}
	if(p1!=-1&&p2!=-1)f[u]=max(f[u],mx1+mx2+1),pd[u]=pd[p1]|pd[p2];
	else {
		if(shit[u].size())pd[u]=1;
		f[u]=max(1ll,f[u]),p1=p2=-1;
	}
	if(p1!=-1)shit[u].erase(p1),shit[u].erase(p2);
	if(pd[u]+f[u]>sze[u])pd[u]=0;
}
signed main(){
	freopen("bird.in","r",stdin);
	freopen("bird.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	int ans=f[1]+pd[1];
	for(auto u:shit[1]){
		ans=max(ans,f[u]+pd[u]);
	}
	cout<<ans<<endl;
	return 0;
}